package org.myspring;

import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
    	// 方式一
    	ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    	HelloWorld2 bean = context.getBean(HelloWorld2.class);
    	HelloWorld2 bean2 = (HelloWorld2) context.getBean("helloworld");
    	System.out.println(bean);
    	System.out.println(bean2);
    	
    	// 方式二 简单工厂
//    	ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    	HelloWorld hw = (HelloWorld) context.getBean("helloworldFactory");
    	System.out.println(hw);
    	
    	// 实例工厂
//    	ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    	HelloWorld3 hw2 = (HelloWorld3) context.getBean("hello3");
    	System.out.println(hw2);
    	
    	HelloWorld4 h4 = context.getBean(HelloWorld4.class);
    	HelloWorld4 h42 = (HelloWorld4)context.getBean("helloworld4");
    	System.out.println(h4);
    	System.out.println(h42);
    	
    	XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
    	HelloWorld4 h43 = (HelloWorld4)factory.getBean(HelloWorld4.class);
    	System.out.println(h43);
    	
    	// applicationContext 加载时就实例化，而bean工厂使用懒加载，使用getBean时才会实例化
    	
    	// 常使用的applicationContext 接口
    	// FileSystemXmlApplicationContext、ClassPathXmlApplicationContext、WebXmlApplicationContext
    	
    	
    }
}
